Repository navigation
Document that ASTHelpers.getSymbol(Tree) returns null for a parenthesized expression - #6297
Merged
Merged
Conversation
…esized expression `ASTHelpers.getSymbol((x))` returns null where `getSymbol(x)` returns the symbol of `x`, and the Javadoc did not say so. A caller that forgets `stripParentheses` gets no symbol for a parenthesized operand, including the expression of every `synchronized` statement, and usually treats that as "not a variable" without any error. As discussed in #6223, the method keeps returning null: callers treat a non-null result as a sign that the tree itself is the identifier, member select, or invocation, and some cast it or pass it to `getReceiver`, which throws `IllegalStateException` when given a parenthesized expression. The Javadoc now states the null result and points at `stripParentheses(Tree)`. A new test in `ASTHelpersTest` pins it, with that reason in its comment, so that a change making `getSymbol` look through parentheses fails it. The old Javadoc also promised null when a compilation error left the symbol unresolved. Error Prone does not run checks on a compilation unit with errors, and an unresolved invocation, `new` expression, or member reference throws `IllegalArgumentException` from its typed overload instead of returning null. The comment now states what the code returns: null for an identifier or member select that javac left without a symbol. The inline comment in `getSymbol` names module names as one such case. `check_api/pom.xml` lists `ASTHelpersTest.java` in `testExcludes`, so the GitHub Maven build does not compile or run the new test. I compiled and ran `ASTHelpersTest` by hand on JDK 25.0.4: all 67 tests pass. With a `ParenthesizedTree` case added at the top of `getSymbol(Tree)`, the new test fails with `expected: null` / `but was : x`. `javadoc -Xdoclint:all` on `ASTHelpers.java` reports no errors; both `{@link}` targets resolve. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Fixes #6295 COPYBARA_INTEGRATE_REVIEW=#6295 from vlsi:claude/javadoc-getsymbol-improvement-ba25fb 4f5b241 PiperOrigin-RevId: 1013782394
copybara-service
Bot
force-pushed
the
test_1013739787
branch
from
November 4, 2026 13:50
c4b4741 to
161c201
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Document that
ASTHelpers.getSymbol(Tree)returns null for a parenthesized expressionASTHelpers.getSymbol((x))returns null wheregetSymbol(x)returns the symbol ofx, and the Javadoc did not say so. A caller that forgetsstripParenthesesgets no symbol for a parenthesized operand, including the expression of everysynchronizedstatement, and usually treats that as "not a variable" without any error.As discussed in #6223, the method keeps returning null: callers treat a non-null result as a sign that the tree itself is the identifier, member select, or invocation, and some cast it or pass it to
getReceiver, which throwsIllegalStateExceptionwhen given a parenthesized expression. The Javadoc now states the null result and points atstripParentheses(Tree). A new test inASTHelpersTestpins it, with that reason in its comment, so that a change makinggetSymbollook through parentheses fails it.The old Javadoc also promised null when a compilation error left the symbol unresolved. Error Prone does not run checks on a compilation unit with errors, and an unresolved invocation,
newexpression, or member reference throwsIllegalArgumentExceptionfrom its typed overload instead of returning null. The comment now states what the code returns: null for an identifier or member select that javac left without a symbol. The inline comment ingetSymbolnames module names as one such case.check_api/pom.xmllistsASTHelpersTest.javaintestExcludes, so the GitHub Maven build does not compile or run the new test. I compiled and ranASTHelpersTestby hand on JDK 25.0.4: all 67 tests pass. With aParenthesizedTreecase added at the top ofgetSymbol(Tree), the new test fails withexpected: null/but was : x.javadoc -Xdoclint:allonASTHelpers.javareports no errors; both{@link}targets resolve.🤖 Generated with Claude Code
Fixes #6295
FUTURE_COPYBARA_INTEGRATE_REVIEW=#6295 from vlsi:claude/javadoc-getsymbol-improvement-ba25fb 4f5b241